package org.dong.Controller;

import org.dong.Dao.FileDaoImpl;
import org.dong.Pojo.Dto;
import org.dong.Pojo.HttpRequest;
import org.dong.Pojo.HttpResponse;
import org.dong.Tool.Data;

import java.io.OutputStream;
import java.util.HashMap;
import java.util.Map;

public class DelFileController implements ServerLet {

    @Override
    public void server(HttpRequest request, OutputStream os) {
        Dto dto = new Dto();
        String msg = "ok";
        //查找数据中是否存在此记录
        String[] list = request.getRequestData().split("&");
        //获取文件ID

        int id = Integer.parseInt(list[0].split("=")[1]);
        Map<String,String> map = new HashMap<>();
        map.put("id",id+"");
        if(new FileDaoImpl().delFile(map)){

            dto.setErrMsg("删除成功");
            dto.setStatusCode(2000);

        } else {

            dto.setStatusCode(2001);
            dto.setErrMsg("没有查找到数据");

        }

        HttpResponse response = new HttpResponse(os,request.getUrl(),msg);

    }
}
